﻿Ext.namespace("Swfu");
Ext.namespace("Swfu.BackMgr");

Swfu.BackMgr.QuestionPanel = Ext.extend(Ext.Panel, { IdNo: 0,
    width:800, height:310,
    id: 'QuestionPanel',
    frame: true,
    initComponent: function () {
        Ext.apply(this, {
            buttons: [{
                text: '保存',
                hidden: false,
                id: 'BtnSave'
            }/*, {
                text: '提交',
                hidden: false,
                id: 'BtnSubmit'
            }*/, {
                text: '取消',
                id: 'BtnCancel',
                handler: function () {
                    var win = Ext.getCmp('QuestionWin');
                    if (!Ext.isEmpty(win)) { win.close(); }
                }
            }],
            items: [
				new Ext.form.FormPanel({
				    id: 'QuestionForm',
				    frame: true,
				    bodyStyle: 'padding:10px',
				    labelWidth: 90,
				    items: [{
				        layout: 'column',
				        border: false,
				        items: [
								{
								    columnWidth: .5,
								    layout: 'form',
								    items: [{
								        fieldLabel: '试题编号',
								        xtype: 'textfield',
								        name: 'Id',
								        id: 'Id',
								        allowBlank: true,
								        readOnly: true,
								        emptyText: '该项值由系统自动生成',
								        blankText: '该项值由系统自动生成',
								        anchor: '100%',
								        disabled: true
								    }]
								}, {
								    columnWidth: .5,
								    layout: 'form',
								    items: [{
								        xtype: 'combo',
								        fieldLabel: '试题类别',
								        name: 'QuestionType',
								        id: 'QuestionType',
								        anchor: '100%',
								        allowBlank: false,
								        displayField: 'lb',
								        valueField: 'lb',
								        hiddenName: 'lb',
								        hiddenId: 'lb',
								        typeAhead: true,
								        mode: 'local',
								        editable: false,
								        selectOnFoucs: true,
								        triggerAction: 'all',
								        blankText: '请选择试题类别',
								        emptyText: '请选择试题类别',
								        store: new Ext.data.SimpleStore({ fields: ['lb'],
								            data: [['判断题'], ['单项选择题'], ['不定项选择题']], autoload: true
								        }),
								        listeners: { scope: this }
								    }]
								}, {
								    columnWidth:1,
								    layout: 'form',
								    items: [{
								        fieldLabel: '问题描述',
								        xtype: 'textarea',
								        name: 'Question',
								        id: 'Question',
								        allowBlank: false,
								        blankText: '请输入问题描述',
								        emptyText: '请输入问题描述',
								        anchor: '100%'
								    }]
								}, {
								    columnWidth:1,
								    layout: 'form',
								    items: [{
								        fieldLabel: '答案选项',
								        xtype: 'textarea',
								        name: 'Options',
								        id: 'Options',
								        height: 100,
								        blankText: '每个选项用"回车(即分行)"放置',
								        emptyText: '每个选项用"回车(即分行)"放置',
								        anchor: '100%'
								    }]
								}, {
								    columnWidth: .5,
								    layout: 'form', height: 28,
								    items: [{
								        fieldLabel: '答案',
								        xtype: 'textfield',
								        name: 'Answer',
								        id: 'Answer',
								        allowBlank: false,
								        emptyText: '该项值不能为空',
								        blankText: '该项值不能为空',
								        anchor: '100%'
								    }]
								}, {
								    columnWidth: .5, height: 28,
								    layout: 'form',
								    items: [{ html: '&nbsp;<br/>&nbsp;'}]
								}]
				    }]
				})
			]
        });

        Swfu.BackMgr.QuestionPanel.superclass.initComponent.apply(this, arguments);
    },
    render: function () {
        Swfu.BackMgr.QuestionPanel.superclass.render.apply(this, arguments);

        if (this.Id !=0) {
            var panel = this;
            Ext.Ajax.request({
                url: '/Exam.mvc/FindByFormNo',
                method: 'POST',
                success: function (response, options) {
                    var record = Ext.util.JSON.decode(response.responseText);

                    Ext.getCmp('Id').setValue(record.Id);
                    Ext.getCmp('QuestionType').setValue(record.QuestionType);
                    Ext.getCmp('Question').setValue(record.Question);
                    Ext.getCmp('Options').setValue(record.Options);
                    Ext.getCmp('Answer').setValue(record.Answer);

                    Ext.getCmp('BtnSave').on('click', function () {fnSubmitQuestion(0, 0); });
                    //Ext.getCmp('BtnSubmit').on('click', function () { fnSubmitQuestion(0, 1); });
                },
                params: {id: this.IdNo},
                failure: function (form, action) {
                    if (action.failureType == 'server') {
                        obj = Ext.util.JSON.decode(action.response.responseText);
                        Ext.Msg.alert('错误:', obj.errors.reason);
                    }
                    if (action.failureType == 'client') {
                        Ext.ux.Toast.msg('提示', '数据不正确，请核对后重新操作');
                    }
                }
            });
        }
    }
});

Ext.reg('QuestionPanel', Swfu.BackMgr.QuestionPanel);